package com.sort;

public class test2 {
  public static void main(String[] args) {
    //合并两个有序数组；
    int[] arr1 = {1, 3, 5, 7, 9};
    int[] arr2 = {2, 4, 6, 8, 10, 12, 14};
    int[] new_arr = new int[arr1.length + arr2.length];
    int arr1_index = 0;
    int arr2_index = 0;
    int new_index = 0;
    while (arr1_index <= arr1.length - 1 & arr2_index <= arr2.length - 1) {
      if (arr1[arr1_index] > arr2[arr2_index]) {
        new_arr[new_index] = arr2[arr2_index];
        arr2_index += 1;
        new_index += 1;
      } else {
        new_arr[new_index] = arr1[arr1_index];
        arr1_index += 1;
        new_index += 1;
      }
    }
    /*System.out.println(arr1_index);
    System.out.println(arr2_index);
    System.out.println(new_index);*/
    while (new_index < new_arr.length) {
      new_arr[new_index] = arr2[arr2_index];
      new_index += 1;
      arr2_index += 1;
    }
    for (int a : new_arr) {
      System.out.print(a + " ");
    }
  }
}
